<?php
session_start();
require_once("../duomiphp/common.php");
require_once(duomi_INC.'/core.class.php');
if($cfg_user==0)
{
	//ShowMsg('系统已关闭会员功能!','-1');
	//exit();
}

$action = isset($action) ? trim($action) : '';
$pg = isset($pg) ? intval($pg) : 1;
$uid=$_SESSION['duomi_user_id'];
if(empty($_SESSION['duomi_user_id']))
{
	showMsg("请先登录","login.php");
	exit();
}

if($action=='chgpwd')
{
/* echo "<div id=\"register\">".
"<form id=\"f_Activation\"   action=\"?action=chgpwdsubmit\" method=\"post\">".
"<table align=\"center\" style=\"margin:0 auto;font-size:12px;\">". 
"<tr>".
"<td height=\"25\" align=\"right\">旧密码:</td><td><input type=\"password\" name=\"oldpwd\" style=\"width:150px\"/><span class=\"red\">*</span>".
"</td>".
"</tr>".
"<tr>".
"<td height=\"25\" align=\"right\">新密码:</td><td><input type=\"password\" name=\"newpwd\" style=\"width:150px\"/></td>".
  "</tr>".
	 "<tr>".
	 	"<td height=\"25\" align=\"right\">确认密码:</td><td><input type=\"password\" name=\"newpwd2\" style=\"width:150px\"/></td>".
  	 "</tr>".
	 "<tr>".
	 	"<td height=\"25\" align=\"right\">Email:</td><td><input type=\"text\" name=\"email\" style=\"width:150px\"/></td>".
  	 "</tr>".
  "<tr>".
	"<td height=\"30\"></td><td><input type=\"submit\" value=\"保存\" class=\"btn\"/></td> </tr>".
"</table></form>".
"</div>"; */
$dsql->setQuery("select * from {$cfg_dbprefix}member_group where gid!=1");
$dsql->Execute('favlist');
$user_group = array();
while($row=$dsql->getArray('favlist')){
	$user_group[] =  $row;
}
$url = $www_root_url."/member/pay/pay_order.php";

echo "<div id='content-right'>
             <div class='memberstatus'>
			     <span>用户名</span>到期时间
             </div>
			 <form action='?action=chgpwdsubmit' id='f_Activation' method='post'>
             <div class='passreset'>
                 <input id='currentPasswordCPW' type='password' placeholder='当前密码' title='Current Password' maxlength='16' name='oldpwd'>
				 <input id='password' type='password' placeholder='新密码' title='New Password' autocomplete='off' maxlength='16' name='newpwd'>
				 <input id='passwordRepeat' type='password' placeholder='确认新密码' title='Confirm New Password' maxlength='16' name='newpwd2'>
				 <span class='box square'><input type=submit class='button ok' value='OK'></span>
             </div>		
			 </form>";
			 
			 foreach($user_group as $k=>$vo){
				 echo "<div class='standard'>
                 <h2>".$vo['gname']."</h2>
                 <p class='price'> $".$vo['g_upgrade']."</p>
             </div>	<a href='{$url}?order_type={$vo['gid']}' target='_blank'>付费</a>";
			 }
             
             			 
		echo "</div>";


}elseif($action=='chgpwdsubmit')
{
	if(trim($newpwd)<>trim($newpwd2))
	{
		ShowMsg('两次输入密码不一致','-1');	
		exit();	
	}


	if(!empty($newpwd)||!empty($email))
	{
	$pwd = empty($newpwd)?substr(md5($oldpwd),5,20):substr(md5($newpwd),5,20);
	$dsql->ExecuteNoneQuery("update `duomi_member` set password = '$pwd' ".(empty($email)?'':",email = '$email'")." where id= '$uid'");
	ShowMsg('密码修改成功','-1');	
	exit();	
	}
		

}
elseif($action=='cancelfav')
{
	$dsql->executeNoneQuery("delete from duomi_favorite where id=".$id);
	echo "<script>location.href='?action=favorite'</script>";
	exit();
}elseif($action=='cancelfavs')
{
	if(empty($fid))
	{
		showMsg("请选择要取消收藏的视频","-1");
		exit();
	}
	foreach($fid as $id)
	{
		$dsql->executeNoneQuery("delete from duomi_favorite where id=".$id);
	}
	echo "<script>location.href='?action=favorite'</script>";
	exit();
}elseif($action=='favorite')
{
	$pcount = 20;
	$row=$dsql->getOne("select count(id) as dd from duomi_favorite where uid=".$uid);
	$rcount=$row['dd'];
	if($rcount==0)
	{
		echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" ><tr><td align=\"center\">没有收藏的视频</td></tr></table>";
		exit();
	}	
	$dsql->setQuery("select * from duomi_favorite where uid=".$uid." limit ".($pg-1)*$pcount.",$pcount");
	$dsql->Execute('favlist');
?>
<html>
<head>
<script src="js/common.js" type="text/javascript"></script>
<script>
function submitForm()
{
	$('favform').submit()
}
function showpic(event,imgsrc){	
	var left = event.clientX+document.documentElement.scrollLeft+20;
	var top = event.clientY+document.documentElement.scrollTop+20;
	$("preview").style.display="";
	$("preview").style.left=left+"px";
	$("preview").style.top=top+"px";
	$("pic_a1").setAttribute('src',imgsrc);
}
function hiddenpic(){
	$("preview").style.display="none";
}
</script>
</head>
<body>
<form id="favform" name="favform" action="?action=cancelfavs" method="post">
<div id="preview" style="position:absolute;display:none;width:100;height:100;" class="showpic"> <img name="pic_a1" id="pic_a1" width="100" height="100"></div>
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="font-size:12px">
  <tr>
    <td colspan="6">共<?php echo $rcount?>个视频，每页显示<?php echo $pcount?>条</td>
  </tr>
  <tr>
    <td><input name="chkall" type="checkbox" onClick="checkAll(this.checked,'input','fid[]')" value=""></td>
    <td align="left">视频</td>
    <td align="left">收藏时间</td>
    <td align="left">播放数</td>
    <td align="left">连载集数</td>
    <td align="left">状态</td>
    <td align="left">操作</td>
  </tr>
  <?php 
while($row=$dsql->getArray('favlist'))
{
	$rs=$dsql->getOne("select v_hit,v_state,v_pic,v_name,v_enname,v_note,v_addtime,tid from duomi_data where v_id=".$row['vid']);
	if(!$rs) {echo "<tr><td align=\"left\"><input type=\"checkbox\"></td><td colspan=\"5\">该视频不存在或已经删除</td></tr>";continue;}
	$hit=$rs['v_hit'];
	$pic=$rs['v_pic'];
	$name=$rs['v_name'];
	$state=$rs['v_state'];
	$note=$rs['v_note'];
?>
  <tr>
    <td align="left"><input name="fid[]" type="checkbox" value="<?php echo $row['id']?>"></td>
    <td align="left"><a href="<?php echo getContentLink($rs['tid'],$row['vid'],"",date('Y-n',$rs['v_addtime']),$rs['v_enname'])?>" target="_blank" onMouseOver="showpic(event,'<?php if(strpos($pic,'uploads')===0)echo '/'.$GLOBALS['cfg_cmspath'].$pic; else echo $pic;?>');" onMouseOut="hiddenpic();"><?php echo $name?></a></td>
    <td align="left"><?php echo date('Y-m-d',$row['kptime'])?></td>
    <td align="left"><?php echo $hit?></td>
    <td align="left"><?php echo $state?></td>
    <td align="left"><?php echo $note?></td>
    <td align="left"><a onClick="return(confirm('确定取消收藏该影片？'))" href="?action=cancelfav&id=<?php echo $row['id']?>">取消收藏</a></td>
  </tr>
  <?php }?>
  <tr>
    <td colspan="6"><input name="chkall" type="checkbox" onClick="checkAll(this.checked,'input','fid[]')" value="<?php echo $row['id']?>" />&nbsp;全选&nbsp;&nbsp;<a href="#" onClick="if(confirm('确定取消收藏该影片？')){submitForm()}else{return false;}">取消收藏</a></td>
  </tr>
  <tr>
    <td colspan="6">共<?php echo $rcount?>个视频，每页显示<?php echo $pcount?>条</td>
  </tr>
</table>
</body>
</form>
</html>
<?php
}else
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>duomicms</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="robots" content="noindex,nofollow" />
<link rel="stylesheet" href="/style/style.css" type="text/css" media="all" />
<style type="text/css">
body{text-align:center;width:100%;font-size:12px;}
.member_head{text-align:left;margin:10px auto;width:800px;height:30px;color:#ffffff;background:#3ca2d2;border:solid 1px #42a8d8;font-size:12px;}
.member_content{width:800px;height:600px;margin:0 auto;}
.member_left{width:108px;height:200px;float:left;border:solid 1px #42a8d8;}
.member_right{width:780px;height:600px;float:left;margin-left:10px;border:solid 1px #42a8d8;}
</style>

</head>
<body>
	<div class="member_head">　个人空间</div>
    <div class="member_content">
    	
    	<div class="member_right">
      		<iframe width="680px" height="600px" frameborder="0" name="member" src="?action=chgpwd"></iframe>  
        </div>        
    
    </div> 
</body>
</html>
<?php
}
?>